export default function ({ $axios, redirect }) {

    // $axios.baseURL = ''; // 默认请求url
    // 请求之前
    $axios.onRequest(config => {
        this.$nuxt.$loading.start()
        $axios.setToken('AuthToken', '')
        console.log('Making request to ' + config.url)
    })
    // 请求之后
    $axios.onResponse(config => {
        // $axios.setToken('AuthToken', '')
        console.log('Making Response to ' + config.url)
        this.$nuxt.$loading.finish()
    })

    $axios.onRequestError(config => {
        console.error('Making request to ' + config.url)
    })

    $axios.onResponseError(config => {
        console.error('Making Response to ' + config.url)
        this.$nuxt.$loading.finish()
    })

    $axios.onError(error => {
        const code = parseInt(error.response && error.response.status)
        if (code === 400) {
            console.error('出错了！')
            redirect('/400')
        }
    })
}